using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.Runtime.Serialization;
using CoreData;
namespace OpenIDHostController.DataContract
{
    [DataContract]
    public class usersContract
    {
        [DataMember]
            public long id{get;set;}
        [DataMember]
            public string username{get;set;}
        [DataMember]
            public string password{get;set;}
        [DataMember]
            public string fullname{get;set;}
        [DataMember]
            public string email{get;set;}
        [DataMember]
            public string address{get;set;}
        [DataMember]
            public string indentitycard{get;set;}
        [DataMember]
            public string numberphone{get;set;}
        [DataMember]
            public bool active{get;set;}
        [DataMember]
            public DateTime createdate{get;set;}
        [DataMember]
            public DateTime modifieddate{get;set;}
        [DataMember]
        public DateTime birthday { get; set; }

        public usersContract()
        {       
                    username ="";   
                    password ="";   
                    fullname ="";   
                    email ="";   
                    address ="";   
                    indentitycard ="";   
                    numberphone ="";   
        }

        public static usersContract ToContract(users data)
        {
            try
            {
                if (data == null) return null;
                var model = ConvertObject.ConvertToObject(new usersContract());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (usersContract)model;
            }
            catch
            {
                return null;
            }
        }
        public static users ToCoreData(usersContract data)
        {
            try
            {
                var model = ConvertObject.ConvertToObject(new users());
                Helper.ConvertObject.ConvertEntityToModel(data, ref model);
                return (users)model;
            }
            catch
            {
                return null;
            }
        }

        public static IList<users> ToListCoreData(IList<usersContract> data)
        {
            var list = new List<users>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new users());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((users)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
        public static IList<usersContract> ToListConTract(IList<users> data)
        {
            var list = new List<usersContract>();
            foreach (var item in data)
            {
                var model = ConvertObject.ConvertToObject(new usersContract());
                Helper.ConvertObject.ConvertEntityToModel(item, ref model);
                if (model != null)
                {
                    list.Add((usersContract)model);
                }
            }
            if (list.Count <= 0)
                return null;
            return list;
        }
        
    }
}
